function getDeviceId(request){
    const headers = request.headers || {};
    console.log(request.url)
    const url = new URL(request.url, 'http://localhost');
    const searchParams = url.searchParams;

    const deviceId =
        headers['device-id'] ||
        headers['deviceId'] ||
        headers['Device-Id'] ||
        headers['device-Id'] ||
        searchParams.get('device-id') || 
        searchParams.get('device-Id') || 
        searchParams.get('deviceId') ||
        searchParams.get('Device-Id');

    return deviceId;
}

function getClientId(request) {
    const headers = request.headers || {};

    const url = new URL(request.url, 'http://localhost');
    const searchParams = url.searchParams;

    const clientId =
        headers['client-id'] ||
        headers['clientId']  ||
        headers['client-Id'] ||
        headers['Client-Id'] ||
        searchParams.get('client-id') || 
        searchParams.get('clientId')  ||
        searchParams.get('client-Id') ||
        searchParams.get('Client-Id');

    return clientId;
}

function getReqIDs(request) {
    const headers = request.headers;
    // const ip = request.socket.remoteAddress;
    console.log(headers)
    const DeviceId = getDeviceId(request) || '-';
    const ClientId = getClientId(request) || '-';

    return `DeviceId: ${DeviceId}, ClientId: ${ClientId}`
}

function getReqIP(request) {
    const headers = request.headers;
    const ip = request.socket.remoteAddress;

    return `IP: ${ip}`
}

module.exports = {
    getDeviceId,
    getClientId,
    getReqIDs,
    getReqIP,
}